<!-- application/views/scripts/manage/index.phtml -->
<?php 

/* @var $v_messages X_Page_ItemList_Message */
$v_messages = $this->messages;

/* @var $v_news X_Page_ItemList_News */
$v_news = $this->news;

/* @var $v_actionLinks X_Page_ItemList_ActionLink */
$v_actionLinks = $this->actionLinks;

/* @var $v_manageLinks X_Page_ItemList_ManageLink */
$v_manageLinks = $this->manageLinks;

/* @var $v_statistics X_Page_ItemList_Statistics */
$v_statistics = $this->statistics;

$pluginApplications = array();
$pluginConfigs = array();

foreach ($v_manageLinks->getItems() as $manageLink) {
	/* @var $manageLink X_Page_Item_ManageLink */
	// only plugin with custom controller goes in topnav
	if ( $manageLink->isUrl() || $manageLink->getLinkController() == 'config' ) {
		//$pluginConfigs[] = $manageLink;
	} else {
		$pluginApplications[] = $manageLink;
	}
}

$this->headTitle()->prepend('Home');

$menu = $this->guiElements()->menu()->setDecorator(X_VlcShares_Skins_Manager::i()->getDecorator(X_VlcShares_Skins_Manager::MENU_CONTEXTUAL));
foreach ( $v_actionLinks->getItems() as $link ) {
	/* @var $link X_Page_Item_ActionLink */
	if ( $link->isUrl() ) {
		$menu->addLink($link->getLabel(), $link->getLink());
	} else {
		$menu->addLinkRoute($link->getLabel(), $link->getLinkController(), $link->getLinkAction(), $link->getLink(), 'default', $link->getRoute(), $link->isReset());
	}
}
$this->layout()->subNavigator =	$menu;

$breadcrumb = $this->guiElements()->menu()
	->setDecorator(X_VlcShares_Skins_Manager::i()->getDecorator(X_VlcShares_Skins_Manager::MENU_BREADCRUMB));
/* @var $breadcrumb X_VlcShares_Elements_Menu */
$this->layout()->breadcrumb = $breadcrumb
	->addLabel(X_Env::_('Dashboard'));
?>

<?php if ( count($v_messages->getItems()) ) :?>
	<ul class="messages">
		<?php foreach ($v_messages->getItems() as $i => $message ): ?>
			<?php /* @var $message X_Page_Item_Message */ ?>
			<li class="<?php echo $message->getType(); ?>">
				<img src="<?php echo @$this->baseUrl("/images/msg_{$message->getType()}.png");?>" alt="<?php echo $message->getType(); ?>" />
				<?php echo $message->getLabel(); ?>
			</li>
		<?php endforeach; ?>
	</ul>
<?php endif; ?>

<?php if ( $v_news != null && count($v_news->getItems()) ) :?>
	<?php /* @var $newsSections X_VlcShares_Elements_SectionContainer */ ?>
	<?php $newsSections = $this->guiElements()->sectionContainer(); ?>
	<?php $newsSections->setSectionsPerRow(2)->setId('news'); // container options ?>
		<?php foreach ($v_news->getItems() as $i => $news) : ?>
			<?php $newsSections->{"news$i"}->setElasticWidth()->start(); ?>
				<?php $block = $this->guiElements()->block(); ?>
				<?php /* @var $block X_VlcShares_Elements_Block */ ?>
				<?php $block->title->set($news->getTab() != '' ? $news->getTab() : $news->getLabel()); ?>
				<?php $block->start(); ?>
					<?php echo $news->getContent(); ?>
				<?php echo $block->end(); ?>
			<?php $newsSections->{"news$i"}->end(); ?>
		<?php endforeach; ?>
	<?php echo $newsSections; ?>
<?php endif; ?>

<?php /* @var $mainSections X_VlcShares_Elements_SectionContainer */ ?>
<?php $mainSections = $this->guiElements()->sectionContainer(); ?>
<?php $mainSections->setSectionsPerRow(5); // container options ?>
	<?php $mainSections->left->setId('plugin-configs')->setSpan(3)->start(); ?>
		<!-- LEFT COLUMN -->
		<?php $block = $this->guiElements()->block(); ?>
		<?php $block->title->set(X_Env::_('p_altgui_plugins')); ?>
		<?php $block->start(); ?>
			<?php if ( count($pluginApplications) ): ?>
				<h2 class="fieldset-header"><?php echo X_Env::_('p_altgui_pluginapplications'); ?></h2>
				<?php /* @var $innerSections X_VlcShares_Elements_SectionContainer */ ?>
				<?php $innerSections = $this->guiElements()->sectionContainer(); ?>
				<?php $innerSections->setSectionsPerRow(4)->setSectionsSameHeight(true); // container options ?>
				<?php foreach ($pluginApplications as $i => $link ): ?>
					<?php /* @var $link X_Page_Item_ManageLink */ ?>
					<?php $innerSections->{"app$i"}->setClasses('config-button')->start(); ?>
						<a class="container full-height" href="<?php echo $link->isUrl() ? $link->getLink() : $this->url($link->getLink(), $link->getRoute(), $link->isReset()); ?>">
							<?php if ( $link->getIcon() != null ):?>
								<img alt="<?php echo $link->getLabel(); ?>" class="thumb" src="<?php echo $this->baseUrl($link->getIcon());?>" />
							<?php else:?>
								<img alt="<?php echo $link->getLabel(); ?>" class="thumb" src="<?php echo $this->baseUrl('/images/manage/plugin.png');?>" />
							<?php endif;?>
							<?php echo $link->getTitle(); ?>
						</a>
					<?php $innerSections->{"app$i"}->end(); ?>
				<?php endforeach; ?>
				<?php echo $innerSections; ?>
			<?php endif; ?>
			
			<?php if ( count($pluginConfigs) ): ?>
				<h2 class="fieldset-header"><?php echo X_Env::_('p_altgui_pluginconfigs'); ?></h2>
				<?php /* @var $innerSections X_VlcShares_Elements_SectionContainer */ ?>
				<?php $innerSections = $this->guiElements()->sectionContainer(); ?>
				<?php $innerSections->setSectionsPerRow(4)->setSectionsSameHeight(true); // container options ?>
				<?php foreach ($pluginConfigs as $i => $link ): ?>
					<?php /* @var $link X_Page_Item_ManageLink */ ?>
					<?php $innerSections->{"conf$i"}->setClasses('config-button')->start(); ?>
						<a class="container full-height" href="<?php echo $link->isUrl() ? $link->getLink() : $this->url($link->getLink(), $link->getRoute(), $link->isReset()); ?>">
							<?php if ( $link->getIcon() != null ):?>
								<img alt="<?php echo $link->getLabel(); ?>" class="thumb" src="<?php echo $this->baseUrl($link->getIcon());?>" />
							<?php else:?>
								<img alt="<?php echo $link->getLabel(); ?>" class="thumb" src="<?php echo $this->baseUrl('/images/manage/plugin.png');?>" />
							<?php endif;?>
							<?php echo $link->getTitle(); ?>
						</a>
					<?php $innerSections->{"conf$i"}->end(); ?>
				<?php endforeach; ?>
				<?php echo $innerSections; ?>
			<?php endif; ?>
		<?php echo $block->end(); ?>
	<?php $mainSections->left->end();?>
	<?php $mainSections->right->setId('statistics')->setSpan(2)->start(); ?>
		<!-- RIGHT COLUMN -->
			<?php foreach ($v_statistics->getItems() as $i => $statistic) : ?>
				<?php /* @var $innerblock X_VlcShares_Elements_InnerBlock */ ?>
				<?php $innerblock = $this->guiElements()->innerBlock(); ?>
				<?php $innerblock->title->set($statistic->getTitle()); ?>
				<?php $innerblock->start(); ?>
					<?php if ( $statistic->getLink() != null ) :?>
						<?php 
						$provider = $statistic->getLink();
						$params = clone $provider;
						unset($params['action']);
						unset($params['controller']);
						unset($params['module']);
						?>
						<?php echo $this->action(
								@$provider['action'],
								@$provider['controller'],
								@$provider['module'],
								@$params); ?>
					<?php else:?>
						<ul>
							<?php foreach ( @$statistic->getStats() as $i => $stat) :?>
								<li><?php echo $stat; ?></li>
							<?php endforeach; ?>
						</ul>
					<?php endif;?>
				<?php echo $innerblock->end(); ?>
			<?php endforeach; ?>			
	<?php $mainSections->right->end();?>
<?php echo $mainSections; ?>
